/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Entry.EntryType;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_76427
/*     */   extends UpgradeOp
/*     */ {
/*  40 */   public static Set<String> standardZimlets = new HashSet();
/*     */   
/*     */   static {
/*  43 */     standardZimlets.add("com_zimbra_adminversioncheck");
/*  44 */     standardZimlets.add("com_zimbra_archive");
/*  45 */     standardZimlets.add("com_zimbra_attachcontacts");
/*  46 */     standardZimlets.add("com_zimbra_attachmail");
/*  47 */     standardZimlets.add("com_zimbra_backuprestore");
/*  48 */     standardZimlets.add("com_zimbra_bulkprovision");
/*  49 */     standardZimlets.add("com_zimbra_cert_manager");
/*  50 */     standardZimlets.add("com_zimbra_click2call_cisco");
/*  51 */     standardZimlets.add("com_zimbra_click2call_mitel");
/*  52 */     standardZimlets.add("com_zimbra_clientuploader");
/*  53 */     standardZimlets.add("com_zimbra_convertd");
/*  54 */     standardZimlets.add("com_zimbra_date");
/*  55 */     standardZimlets.add("com_zimbra_delegatedadmin");
/*  56 */     standardZimlets.add("com_zimbra_email");
/*  57 */     standardZimlets.add("com_zimbra_hsm");
/*  58 */     standardZimlets.add("com_zimbra_license");
/*  59 */     standardZimlets.add("com_zimbra_mobilesync");
/*  60 */     standardZimlets.add("com_zimbra_phone");
/*  61 */     standardZimlets.add("com_zimbra_proxy_config");
/*  62 */     standardZimlets.add("com_zimbra_smime");
/*  63 */     standardZimlets.add("com_zimbra_smime_cert_admin");
/*  64 */     standardZimlets.add("com_zimbra_srchhighlighter");
/*  65 */     standardZimlets.add("com_zimbra_tooltip");
/*  66 */     standardZimlets.add("com_zimbra_ucconfig");
/*  67 */     standardZimlets.add("com_zimbra_url");
/*  68 */     standardZimlets.add("com_zimbra_viewmail");
/*  69 */     standardZimlets.add("com_zimbra_voiceprefs");
/*  70 */     standardZimlets.add("com_zimbra_webex");
/*  71 */     standardZimlets.add("com_zimbra_xmbxsearch");
/*  72 */     standardZimlets.add("com_zimbra_ymemoticons");
/*     */   }
/*     */   
/*     */   void doUpgrade() throws ServiceException
/*     */   {
/*  77 */     ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
/*     */     try {
/*  79 */       doGlobalConfig(zlc);
/*  80 */       doAllDomain(zlc);
/*  81 */       doAllCos(zlc);
/*     */     } finally {
/*  83 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */   }
/*     */   
/*     */   private void doEntry(ZLdapContext zlc, Entry entry, String entryName, String attr) throws ServiceException
/*     */   {
/*  89 */     this.printer.println();
/*  90 */     this.printer.println("------------------------------");
/*  91 */     this.printer.println("Upgrading " + entryName + ": ");
/*     */     
/*  93 */     if (this.verbose) {
/*  94 */       this.printer.println("");
/*  95 */       this.printer.println("Checking " + entryName + ", attribute: " + attr);
/*     */     }
/*     */     
/*  98 */     Set<String> values = entry.getMultiAttrSet(attr);
/*  99 */     if (values.isEmpty()) {
/* 100 */       if (this.verbose) {
/* 101 */         this.printer.println("Current value is empty. No changes needed for " + entryName + ", attribute: " + attr);
/*     */       }
/* 103 */       return;
/*     */     }
/*     */     
/* 106 */     boolean modified = false;
/* 107 */     Map<String, Object> attrs = new HashMap();
/* 108 */     for (String value : values) {
/* 109 */       String zimletName = value;
/* 110 */       if ((value.startsWith("!")) || (value.startsWith("+")) || (value.startsWith("-"))) {
/* 111 */         zimletName = value.substring(1);
/*     */       }
/* 113 */       if ((!standardZimlets.contains(zimletName)) && (!value.startsWith("-"))) {
/* 114 */         StringUtil.addToMultiMap(attrs, attr, "-" + zimletName);
/* 115 */         modified = true;
/*     */       } else {
/* 117 */         StringUtil.addToMultiMap(attrs, attr, value);
/*     */       }
/*     */     }
/*     */     
/* 121 */     if (!modified) {
/* 122 */       if (this.verbose) {
/* 123 */         this.printer.println("No changes needed for " + entryName + ", attribute: " + attr);
/*     */       }
/* 125 */       return;
/*     */     }
/*     */     try
/*     */     {
/* 129 */       modifyAttrs(zlc, entry, attrs);
/*     */     }
/*     */     catch (ServiceException e) {
/* 132 */       this.printer.println("Caught ServiceException while modifying " + entryName + " attribute " + attr);
/* 133 */       this.printer.printStackTrace(e);
/*     */     }
/*     */   }
/*     */   
/*     */   private void doGlobalConfig(ZLdapContext zlc) throws ServiceException {
/* 138 */     Config config = this.prov.getConfig();
/* 139 */     doEntry(zlc, config, "global config", "zimbraZimletDomainAvailableZimlets");
/*     */   }
/*     */   
/*     */   private void doAllDomain(ZLdapContext zlc) throws ServiceException {
/* 143 */     List<Domain> domains = this.prov.getAllDomains();
/* 144 */     for (Domain domain : domains) {
/* 145 */       String name = "domain " + domain.getName();
/* 146 */       doEntry(zlc, domain, name, "zimbraZimletDomainAvailableZimlets");
/*     */     }
/*     */   }
/*     */   
/*     */   private void doAllCos(ZLdapContext zlc) throws ServiceException {
/* 151 */     List<Cos> coses = this.prov.getAllCos();
/* 152 */     for (Cos cos : coses) {
/* 153 */       String name = "cos " + cos.getName();
/* 154 */       doEntry(zlc, cos, name, "zimbraZimletAvailableZimlets");
/*     */     }
/*     */   }
/*     */   
/*     */   Description getDescription()
/*     */   {
/* 160 */     return new Description(this, new String[] { "zimbraZimletAvailableZimlets", "zimbraZimletDomainAvailableZimlets" }, new Entry.EntryType[] { Entry.EntryType.DOMAIN, Entry.EntryType.COS }, "[Current Zimlets]", standardZimlets.toString(), "Disable all non-standard Zimlets.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_76427.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */